#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from dragon.selector import Selector
from dragon.page import DraPage
from pages.calendar import Calendar
from pages.strategybar import StrategyBar


class StockTrack5Se:
    calendarButton = Selector('.operate-time>div.bkvalue', '日历按钮')
    sortButton=Selector('text=排序','排序按钮')
    conformButton=Selector('text=确定','确定按钮')
    acoButton=Selector('text=竞/流/开','竞流开按钮')
    labelButton=Selector('text=选择标签','标签按钮')
    # 排序按钮
    changeCountSortButton=Selector('text=资金次数','资金次数排序按钮')
    increaseSortButton=Selector(':text-is("涨幅")','涨幅排序按钮')
    includeTimeSortButton=Selector(':text-is("纳入时间")','纳入时间排序按钮')
    changeTimeSortButton=Selector(':text-is("时间")','异动时间排序按钮')

    # 股票列表
    stockBlock = Selector('li.infinite-list-item', '股票块')
    stock = Selector('div.demo6-item-name', '股票')
    stockCode = Selector('div.demo6-item-name>span:nth-child(2)', '股票代码')
    changeCount = Selector('.demo6-item-moneyNum>span', '异动次数')
    changeTime = Selector('.demo6-item-moneyNum :text(":")', '异动时间')
    realtimeIncrease = Selector('.item-head :text("%")', '实时涨幅')
    includeTime=Selector('text=纳入时间：','纳入时间')
    notMatchAlert = Selector('div.empty-text', '空数据提示')
    labelBar = Selector('div.labels', '标签栏')
    # 详情
    detailButton = Selector(':text-is("详情")', '详情按钮')
    detailChangeTime = Selector('div.demo5-detil :text(":")', '详情异动时间')
    detailNohistoryAlert = Selector('text=当前没有历史数据', '无历史数据提示')
    changeIncrease = Selector('.demo5-yidong>div', '异动涨幅')
    auction = Selector('text=集合竞价', '集合竞价')
    circulation = Selector('text=流通值', '流通值')
    openVolume = Selector('text=开盘量', '开盘量')


class StockTrackPage5(StrategyBar):
    def __init__(self, draPage: DraPage):
        super().__init__(draPage)
        self.draPage = draPage
        self.calendarButton = draPage.locator(StockTrack5Se.calendarButton)
        '''日历按钮'''
        self.sortButton=draPage.locator(StockTrack5Se.sortButton)
        '''排序按钮'''
        self.changeCountSortButton=draPage.locator(StockTrack5Se.changeCountSortButton)
        '''资金次数按钮'''
        self.conformButton=draPage.locator(StockTrack5Se.conformButton)
        '''确认按钮'''
        self.acoButton=draPage.locator(StockTrack5Se.acoButton)
        '''竞流开按钮'''
        self.labelButton=draPage.locator(StockTrack5Se.labelButton)
        self.increaseSortButton=draPage.locator(StockTrack5Se.increaseSortButton)
        self.includeTimeSortButton=draPage.locator(StockTrack5Se.includeTimeSortButton)
        self.changeTimeSortButton=draPage.locator(StockTrack5Se.changeTimeSortButton)
        self.stockBlock = draPage.locator(StockTrack5Se.stockBlock)
        self.stock = draPage.locator(StockTrack5Se.stock)
        self.stockCode = draPage.locator(StockTrack5Se.stockCode)
        self.changeCount = draPage.locator(StockTrack5Se.changeCount)
        self.changeTime = draPage.locator(StockTrack5Se.changeTime)
        self.realtimeIncrease = draPage.locator(StockTrack5Se.realtimeIncrease)
        self.includeTime = draPage.locator(StockTrack5Se.includeTime)
        self.labelBar = draPage.locator(StockTrack5Se.labelBar)
        self.notMatchAlert = draPage.locator(StockTrack5Se.notMatchAlert)
        self.detailButton = draPage.locator(StockTrack5Se.detailButton)
        self.detailChangeTime = draPage.locator(StockTrack5Se.detailChangeTime)
        self.detailNohistoryAlert = draPage.locator(StockTrack5Se.detailNohistoryAlert)
        self.changeIncrease = draPage.locator(StockTrack5Se.changeIncrease)
        self.auction = draPage.locator(StockTrack5Se.auction)
        self.circulation = draPage.locator(StockTrack5Se.circulation)
        self.openVolume = draPage.locator(StockTrack5Se.openVolume)

    def pick_date_by_index(self, index: int):
        self.calendarButton.click()
        calendar = Calendar(self.draPage)
        calendar.pick_date_by_index(index)
